/*
 * FixedLengthMessage.h
 *
 *  Created on: Jul 19, 2013
 *      Author: m
 */

#ifndef FIXEDLENGTHMESSAGE_H_
#define FIXEDLENGTHMESSAGE_H_

#include <cstring>
#include <string>
#include "communication_common.h"

#define MESSAGE_MAX_LENGTH 1024
#define ADDRESS_MAX_LENGTH 26

namespace communication
{

class FixedLengthMessage
{
protected:
    size_t m_size;
    char m_destination[ADDRESS_MAX_LENGTH];
    char m_data[MESSAGE_MAX_LENGTH];

public:

    FixedLengthMessage() :
        m_size( 0 )
    {
    }

    FixedLengthMessage( size_t size, const char* data, std::string destination ) :
        m_size( size )
    {
        strncpy( m_destination, destination.c_str(), ADDRESS_MAX_LENGTH );
        memcpy( m_data, data, m_size );
    }

    FixedLengthMessage( const FixedLengthMessage &rhs )
    {
        *this = rhs;
    }

    size_t getSize()
    {
        return m_size;
    }

    const char* getData()
    {
        return m_data;
    }

    std::string getDestination()
    {
        return std::string( m_destination );
    }

    FixedLengthMessage& operator=( const FixedLengthMessage &rhs )
    {
        if ( this != &rhs )
        {
            m_size = rhs.m_size;
            strncpy( m_destination, rhs.m_destination, ADDRESS_MAX_LENGTH );
            memcpy( m_data, rhs.m_data, rhs.m_size );
        }

        return *this;
    }
};

} /* namespace communication */
#endif /* FIXEDLENGTHMESSAGE_H_ */
